<?php
/**
 * Created by PhpStorm.
 * User: SCKJ
 * Date: 16/1/9
 * Time: 下午5:40
 */
namespace Utils;

use GatewayWorker\Lib\Gateway;

class AlertMsg {

    private $alert_arr;

    private $recId;

    public function __construct($message,$reciveId,$ope,$type)
    {
        $this->alert_arr = array();

        //event
        $this->alert_arr[EVENT] = EVENT_ALERT_MSG;

        //data
        $data = array();
        $data[MESSAGE] = $message;
        $data[OPERATION] = $ope;
        $data[TYPE] = $type;
        $this->alert_arr[DATA] = $data;

        $this->recId = $reciveId;
    }

    public static function sendAlert($message,$reciveId,$ope = 'normal',$type = ALERT_TYPE_NOTICE)
    {
        $body = new AlertMsg($message,$reciveId,$ope,$type);
        $body->send();
        return null;
    }

    public function send()
    {
//        Gateway::sendToCurrentClient(json_encode($this->alert_arr));
        print $this->recId;
        print_r(Gateway::getClientIdByUid($this->recId));

        Gateway::sendToUid($this->recId,json_encode($this->alert_arr));
    }
}